package android.academy.haixue.com.haixue.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ren on 2015/5/4 0004.
 */
public abstract class CustomBaseAdapter<T> extends BaseAdapter{
    protected final Context context;
    protected final  List<T> datas = new ArrayList<T>();

    public CustomBaseAdapter(Context context){
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public T getData(int position){
      return  datas.get(position);
    }

    public void setDatas(List<T> data) {
        if (data != null&&datas.size()>0)
            return;
        datas.clear();
        datas.addAll(data);
        notifyDataSetChanged();
    }

    public void addDatas(List<T> data) {
        if (data != null&&datas.size()>0)
            return;
        datas.addAll(data);
        notifyDataSetChanged();
    }

    public void clear() {
        datas.clear();
    }
}
